package com.tl.commonlibrary.storage.filecache;

import android.content.Context;
import android.os.Environment;
import android.os.StatFs;

import java.io.File;

/**
 * Created by jiangzhongshan on 15/7/29.
 */
public class CacheConfig {

    private File cacheDir ;
    private long mCacheTime = 0;
    private long cacheSize = 0;
    public CacheConfig(Context context){
        this(context.getExternalCacheDir());
    }
    public CacheConfig(File cachePathFile){
        cacheDir = cachePathFile;
        File root = Environment.getExternalStorageDirectory();
        if(root != null) {
            StatFs statFs = new StatFs(root.getPath());
            System.out.println("statFs.getBlockSize() " + statFs.getBlockSize() + "---statFs.getAvailableBlocks() " + statFs.getAvailableBlocks());
            cacheSize = statFs.getAvailableBlocks() * (long) statFs.getBlockSize();//statFs.getAvailableBlocks()* statFs.getBlockSize()-100*1024*1024;
            System.out.println("cache size is " + cacheSize + "---MB " + cacheSize / 1048576);
        }
        if(cacheSize <0){
            cacheSize = 0;
        }
//        Formatter.formatFileSize();

    }
    public long getCacheSize() {
        return cacheSize;
    }

    public void setCacheSize(long cacheSize) {
        this.cacheSize = cacheSize;
    }

    public File getCacheDir() {
        return cacheDir;
    }

    public void setCacheDir(File cacheDir) {
        this.cacheDir = cacheDir;
    }

    public long getmCacheTime() {
        return mCacheTime;
    }

    /**
     * 缓存的时长
     * @param mCacheTime
     */
    public void setmCacheTime(long mCacheTime) {
        this.mCacheTime = mCacheTime;
    }
}
